/*
 * Thomas Weichselbaumer
 * mini-drone
 * main.c
 *
 */

#include <LPC214x.h>
#include "serial.h"
#include "macros.h"

#define CR     0x0D

extern void init_serial (void)
{
	/* Enable Pins */
    /*setbit(PINSEL0,1,0);*/
    
    /*TODO REFACTOR*/
    PINSEL0 = 0x00000005;    /* Enable RxD0 and TxD0              */
    U0LCR = 0x83;                        /* 8 bits, no Parity, 1 Stop bit     */
    U0DLL = 97;                           /* 9600 Baud Rate @ 15MHz VPB Clock  */
    U0LCR = 0x03;
}

extern int sendchar (int ch)  
{                 /* Write character to Serial Port    */
    if (ch == '\n')
    {
        while (!(U0LSR & 0x20));
        U0THR = CR;                          /* output CR */
    }
    while (!(U0LSR & 0x20));
    return (U0THR = ch);
}


extern int getkey (void)  {                     /* Read character from Serial Port   */

  while (!(U0LSR & 0x01));

  return (U0RBR);
}
